package com.hsy.sunflowerbao.base.ui.widget

import android.content.Context
import android.os.CountDownTimer
import android.widget.TextView

import com.flux.utils.LogUtil
import com.hsy.sunflowerbao.R

/**
 * 定时器
 * Created on 2017/2/12.
 *
 * @author Yang
 */
class TimeCount(millisInFuture: Long, countDownInterval: Long, private val code: TextView, private val mContext: Context) : CountDownTimer(millisInFuture, countDownInterval) {

    var isRunning = false

    override fun onTick(millisUntilFinished: Long) {
        if (millisUntilFinished / 1000 == 0L) {
            onFinish()
        } else {

            isRunning = true
            val sendAgain = mContext.getString(R.string.get_code_again)
            code.text = sendAgain + "(" + millisUntilFinished / 1000 + "s" + ")"
            LogUtil.d("time=" + millisUntilFinished / 1000)
            code.isClickable = false
        }
    }

    override fun onFinish() {
        isRunning = false
        val str = mContext.getString(R.string.button_get_auth)
        code.text = str
        code.isClickable = true
    }
}
